home *** CD-ROM | disk | FTP | other *** search
- #include <iostream.h>
- #include "Parse.H"
- #include <ctype.h>
-
- int
- number(Parse &P, int& value)
- {
- Token tok;
-
- P, NUMBER(tok);
- if( P ) {
- int i = isdigit(tok[0])?0:1;
- for( value = 0; i < tok.length(); i++ ) {
- value = value * 10 + (tok[i] - '0');
- }
- if( tok[0] == '-' ) {
- value = -value;
- }
- }
- return P;
- }
-
- int
- Break(Parse& P)
- {
- int fleet;
- int amt;
-
- P , 'B', MATCH(number, fleet), MATCH(number, amt), CHOOSE(1),
- OR, 'B', "MAX", MATCH(number, amt), CHOOSE(2);
-
- switch(P()) {
- case 0: {
- cout << "no match" << endl;
- break;
- }
- case 1: {
- cout << fleet << ' ' << amt << endl;
- break;
- }
- case 2: {
- cout << "MAX " << amt << endl;
- break;
- }
- }
- return P;
- }
-
- main()
- {
- Parse P("foo");
- Token x;
- P, MATCH(Break);
- cout << P << ' ' << P() << endl;
- }
-